package com.study.hot.di.kodein

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.study.hot.R
import org.kodein.di.KodeinAware
import org.kodein.di.android.closestKodein
import org.kodein.di.generic.instance
import javax.sql.DataSource

/**
 * <pre>
 *     author : slx
 *     time   : 2020/11/28
 *     desc   : 依赖注入默认都是懒加载
 * </pre>
 */

/*
* Kodein原理是——将依赖交给一个 Kodein容器，然后将Kodein容器交给Activity，Activity中所需要的依赖通过委托给Kodein容器注入
* */
class KodeinActivity : AppCompatActivity(), KodeinAware {

    // 通过closestKodein 恢复 Application级别的 Kodein
    override val kodein by closestKodein()

    val ds: DataSource by instance()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_kodein)
        println(ds)

        // 取消懒加载
        // kodeinTrigger?.trigger()
    }
}